package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.dto.ItemDoc;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author liCuiPing
 * @since 2022/12/9 16:29
 */
@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索栏补全词
     * @param key
     * @return
     */
    @GetMapping("suggestion")
    public List<String> suggestionSearch(@RequestParam("key") String key) {
        return searchService.suggestionSearch(key);
    }

    /**
     * 聚合
     * @return
     */
    @PostMapping("filters")
    public Map<String,List<String>> filter(@RequestBody com.hmall.search.pojo.RequestParam requestParam ) {
       return searchService.filter(requestParam) ;
    }

    /**
     * es分页搜索
     * @return
     */
    @PostMapping("list")
    public PageDTO<ItemDoc> pageSearch(@RequestBody com.hmall.search.pojo.RequestParam requestParam) {
        return searchService.listPage(requestParam);
    }
}